package com.broada.apm.model;

import java.io.Serializable;

/**
 * 统计维度
 * 
 * @author sam Create By 2014年11月19日 下午2:12:42
 */
public class Dimension implements Serializable {
	/**
	 * <code>serialVersionUID</code>
	 */
	private static final long serialVersionUID = 1L;
	private String id;
	private String name;
	private String type;
	private String code;
	private int order;
	/*
	 * 维度来源，指维度是根据REQUEST数据包定位，还是根据RESPONSE数据包定位
	 */
	private DimensionSourceType source;
	public static enum DimensionSourceType {
		REQUEST, RESPONSE;
	}
	public Dimension(String type,DimensionSourceType source) {
		this.type = type;
		this.source = source;
	}

	public String getType() {
		return type;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public void setType(String type) {
		this.type = type;
	}

	public int getOrder() {
		return order;
	}

	public void setOrder(int order) {
		this.order = order;
	}

	public DimensionSourceType getSource() {
		return source;
	}

	public void setSource(DimensionSourceType source) {
		this.source = source;
	}

	@Override
	public String toString() {
		return "Dimension [id=" + id + ", name=" + name + ", type=" + type + "]";
	}

	/**
	 * 浏览器
	 * 
	 */
	public static class Browser extends Dimension {

		public Browser() {
			super("browser",DimensionSourceType.REQUEST);
		}

		protected Browser(String id, String code, String name) {
			super("browser",DimensionSourceType.REQUEST);
			setId(id);
			setName(name);
			setCode(code);
		}

		/**
		 * <code>serialVersionUID</code>
		 */
		private static final long serialVersionUID = 1L;
	}

	/**
	 * 设备类型
	 * 
	 */
	public static class Device extends Dimension {

		public Device() {
			super("device",DimensionSourceType.REQUEST);
		}

		/**
		 * <code>serialVersionUID</code>
		 */
		private static final long serialVersionUID = 1L;

	}

	/**
	 * 地理位置
	 * 
	 */
	public static class Area extends Dimension {
		/**
		 * <code>serialVersionUID</code>
		 */
		private static final long serialVersionUID = 1L;

		public Area() {
			this("", "");
		}

		public Area(String id, String name) {
			super("area",DimensionSourceType.REQUEST);
			setId(id);
			setName(name);
		}
		public Area(String id, String name,String code) {
			super("area",DimensionSourceType.REQUEST);
			setId(id);
			setName(name);
			setCode(code);
		}
		public static final Area UNKNOWN = new Area("UNKNOWN", "UNKNOWN");
	}

	/**
	 * 操作系统
	 */
	public static class OS extends Dimension {

		public OS() {
			super("os",DimensionSourceType.REQUEST);
		}

		/**
		 * <code>serialVersionUID</code>
		 */
		private static final long serialVersionUID = 1L;

	}

	/**
	 * 错误码
	 */
	public static class Error extends Dimension {
		public static int STATUS_OK = 0, STATUS_ERROR = 1, STATUS_IGORNE = 2;
		public static int CREATEBY_MODULE = 0, CREATEBY_SYSTEM = 1;
		private String errorMessage;
		private int protocol;
		/**状态：
		 * 0 正确 这个返回码是正常的业务请求返回
		 * 1 错误 这个返回码是错误的业务返回
		 * 2 忽略 这个返回码是可以忽略的，不计入指标运算
		*/ 
		private int status;
		/**
		 * 由创建者
		 * 0 module模块导入
		 * 1 自动发现
		 */
		private int createBy;
		public int getProtocol() {
			return protocol;
		}

		public void setProtocol(int protocol) {
			this.protocol = protocol;
		}

		public String getErrorMessage() {
			return errorMessage;
		}

		public void setErrorMessage(String errorMessage) {
			this.errorMessage = errorMessage;
		}

		public Error() {
			super("error",DimensionSourceType.RESPONSE);
		}
		public Error(String id, String code, String name) {
			super("error",DimensionSourceType.RESPONSE);
			setId(id);
			setName(name);
			setCode(code);
		}
		public void setStatus(int status) {
			this.status = status;
		}
		public int getStatus() {
			return status;
		}
		public void setCreateBy(int createBy) {
			this.createBy = createBy;
		}
		public int getCreateBy() {
			return createBy;
		}
		public boolean isError() {
			return status == STATUS_ERROR;
		}
		public boolean isIgorne() {
			return status == STATUS_IGORNE;
		}
		public boolean isOk() {
			return status == STATUS_OK;
		}
		/**
		 * <code>serialVersionUID</code>
		 */
		private static final long serialVersionUID = 1L;

	}
}
